package com.ebt.m.proposal_v2.adapter;

import android.content.Context;
import android.view.View;

import com.ebt.m.R;
import com.ebt.m.proposal_v2.bean.InsuranceEntity;
import com.ebt.m.proposal_v2.dao.response.ResponseChanShuoItem;
import com.ebt.m.proposal_v2.helper.ThemeHelper;
import com.ebt.m.proposal_v2.interfaces.OnRxClickListener;
import com.ebt.m.proposal_v2.utils.ProposalUtils;
import com.ebt.m.proposal_v2.utils.RxUtils;
import com.ebt.m.proposal_v2.widget.view.CompoundTextView;

import butterknife.BindView;

/**
 * Created by Rick.Wang on 2017/12/26.
 */

public class ProductInProposalViewHolder extends EBTRecyclerAdapter.EBTRecyclerViewHolder<ResponseChanShuoItem> {
    @BindView(R.id.product_label)
    CompoundTextView productView;

    public ProductInProposalViewHolder(Context context, View itemView) {
        super(context, itemView);
    }

    @Override
    protected void onBindView(View itemView, ResponseChanShuoItem data, int position) {
        setProductLabel(data.isMain());
        setProductName(data.productName);
        bindListener(data);
    }

    private void setProductLabel(boolean isMain) {
        if (isMain) {
            productView.setLeftDrawable(ThemeHelper.getDrawable(getContext(), R.drawable.ic_label_main));
        } else {
            productView.setLeftDrawable(ThemeHelper.getDrawable(getContext(), R.drawable.ic_label_additional));
        }
    }

    private void setProductName(String productName) {
        productView.setText(productName == null ? "" : productName);
    }

    private void bindListener(ResponseChanShuoItem data) {
        RxUtils.click(itemView, new RxClickListener(getContext(), data));
    }

    private static class RxClickListener implements OnRxClickListener {
        private Context mContext;
        private ResponseChanShuoItem mData;

        public RxClickListener(Context context, ResponseChanShuoItem data) {
            this.mContext = context;
            this.mData = data;
        }

        @Override
        public void onRxClick(View view) {
            ProposalUtils.startProductDetailNewFromProposalMaking(mContext, mData.productId);
        }
    }
}